<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-envoy" tabindex="-1"><a class="header-anchor" href="#laravel-envoy"><span>Laravel Envoy</span></a></h2>
<ul>
<li><a href="#introduction">简介</a></li>
<li><a href="#installation">安装</a></li>
<li><a href="#writing-tasks">编写任务</a>
<ul>
<li><a href="#defining-tasks">定义任务</a></li>
<li><a href="#multiple-servers">多服务器</a></li>
<li><a href="#setup">设置</a></li>
<li><a href="#variables">变量</a></li>
<li><a href="#stories">故事</a></li>
<li><a href="#completion-hooks">钩子</a></li>
</ul>
</li>
<li><a href="#running-tasks">运行任务</a>
<ul>
<li><a href="#confirming-task-execution">确认任务执行</a></li>
</ul>
</li>
<li><a href="#notifications">通知</a>
<ul>
<li><a href="#slack">Slack</a></li>
<li><a href="#discord">Discord</a></li>
<li><a href="#telegram">Telegram</a></li>
<li><a href="#microsoft-teams">Microsoft Teams</a></li>
</ul>
</li>
</ul>
<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2>
<p><a href="https://github.com/laravel/envoy" target="_blank" rel="noopener noreferrer">Laravel Envoy</a> 是一个用于在远程服务器上执行常见任务的工具。使用 <a href="https://learnku.com/docs/laravel/11.x/blade" target="_blank" rel="noopener noreferrer">Blade</a> 风格的语法，你可以轻松设置部署、Artisan 命令等任务。目前，Envoy 仅支持 Mac 和 Linux 操作系统。不过，使用 <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" target="_blank" rel="noopener noreferrer">WSL2</a> 可以实现对 Windows 的支持。</p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>首先，使用 Composer 包管理器将 Envoy 安装到你的项目中：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/envoy <span class="token parameter variable">--dev</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装 Envoy 后，Envoy 二进制文件将可在你的应用程序的 <code v-pre>vendor/bin</code> 目录中找到：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php vendor/bin/envoy</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="编写任务" tabindex="-1"><a class="header-anchor" href="#编写任务"><span>编写任务</span></a></h2>
<h3 id="定义任务" tabindex="-1"><a class="header-anchor" href="#定义任务"><span>定义任务</span></a></h3>
<p>任务是 Envoy 的基本构建块。任务定义了在调用任务时应在其远程服务器上执行的 shell 命令。例如，你可以定义一个任务，在所有应用程序的队列工作服务器上执行 <code v-pre>php artisan queue:restart</code> 命令。</p>
<p>你所有的 Envoy 任务都应在应用程序根目录下的 <code v-pre>Envoy.blade.php</code> 文件中定义。以下是一个入门示例：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['web' =&gt; ['user@192.168.1.1'], 'workers' =&gt; ['user@192.168.1.2']])</span>
<span class="line"></span>
<span class="line">@task('restart-queues', ['on' =&gt; 'workers'])</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    php artisan queue:restart</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如你所见，文件顶部定义了一个 <code v-pre>@servers</code> 数组，允许你通过任务声明的 <code v-pre>on</code> 选项引用这些服务器。<code v-pre>@servers</code> 声明应始终放在一行上。在你的 <code v-pre>@task</code> 声明中，应放置任务调用时在其服务器上执行的 shell 命令。</p>
<h4 id="本地任务" tabindex="-1"><a class="header-anchor" href="#本地任务"><span>本地任务</span></a></h4>
<p>你可以通过将服务器的 IP 地址指定为 <code v-pre>127.0.0.1</code> 来强制脚本在本地计算机上运行：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['localhost' =&gt; '127.0.0.1'])</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="导入-envoy-任务" tabindex="-1"><a class="header-anchor" href="#导入-envoy-任务"><span>导入 Envoy 任务</span></a></h4>
<p>使用 <code v-pre>@import</code> 指令，你可以导入其他 Envoy 文件，以便它们的脚本和任务被添加到你的文件中。导入文件后，可以执行它们包含的任务，就像它们是在你自己的 Envoy 文件中定义的一样：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@import('vendor/package/Envoy.blade.php')</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="多服务器" tabindex="-1"><a class="header-anchor" href="#多服务器"><span>多服务器</span></a></h3>
<p>Envoy 允许你轻松地在多个服务器上运行任务。首先，将其他服务器添加到你的 <code v-pre>@servers</code> 声明中。每个服务器应分配一个唯一的名称。定义其他服务器后，可以在任务的 <code v-pre>on</code> 数组中列出每个服务器：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['web-1' =&gt; '192.168.1.1', 'web-2' =&gt; '192.168.1.2'])</span>
<span class="line"></span>
<span class="line">@task('deploy', ['on' =&gt; ['web-1', 'web-2']])</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    git pull origin {{ $branch }}</span>
<span class="line">    php artisan migrate --force</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="并行执行" tabindex="-1"><a class="header-anchor" href="#并行执行"><span>并行执行</span></a></h4>
<p>默认情况下，任务将按顺序在每个服务器上执行。换句话说，任务将在第一个服务器上完成运行后才继续在第二个服务器上执行。如果你希望在多个服务器上并行运行任务，请在任务声明中添加 <code v-pre>parallel</code> 选项：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['web-1' =&gt; '192.168.1.1', 'web-2' =&gt; '192.168.1.2'])</span>
<span class="line"></span>
<span class="line">@task('deploy', ['on' =&gt; ['web-1', 'web-2'], 'parallel' =&gt; true])</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    git pull origin {{ $branch }}</span>
<span class="line">    php artisan migrate --force</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="设置" tabindex="-1"><a class="header-anchor" href="#设置"><span>设置</span></a></h3>
<p>有时，你可能需要在运行 Envoy 任务之前执行任意 PHP 代码。你可以使用 <code v-pre>@setup</code> 指令定义一个应在任务之前执行的 PHP 代码块：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">@<span class="token class-name type-declaration">setup</span></span>
<span class="line">    <span class="token variable">$now</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DateTime</span><span class="token punctuation">;</span></span>
<span class="line">@endsetup</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果在任务执行之前需要加载其他 PHP 文件，可以在 <code v-pre>Envoy.blade.php</code> 文件顶部使用 <code v-pre>@include</code> 指令：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@include('vendor/autoload.php')</span>
<span class="line"></span>
<span class="line">@task('restart-queues')</span>
<span class="line">    # ...</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="变量" tabindex="-1"><a class="header-anchor" href="#变量"><span>变量</span></a></h3>
<p>如果需要，你可以在调用 Envoy 时，在命令行上指定参数来传递给 Envoy 任务：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php vendor/bin/envoy run deploy <span class="token parameter variable">--branch</span><span class="token operator">=</span>master</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>你可以在任务中使用 Blade 的「echo」语法访问这些选项。还可以在任务中定义 Blade 的 <code v-pre>if</code> 语句和循环。例如，让我们在执行 <code v-pre>git pull</code> 命令之前验证 <code v-pre>$branch</code> 变量的存在：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['web' =&gt; ['user@192.168.1.1']])</span>
<span class="line"></span>
<span class="line">@task('deploy', ['on' =&gt; 'web'])</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line"></span>
<span class="line">    @if ($branch)</span>
<span class="line">        git pull origin {{ $branch }}</span>
<span class="line">    @endif</span>
<span class="line"></span>
<span class="line">    php artisan migrate --force</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="故事" tabindex="-1"><a class="header-anchor" href="#故事"><span>故事</span></a></h3>
<p>故事将一组任务分组在一个方便的名称下。例如，<code v-pre>deploy</code> 故事可以通过在其定义中列出任务名称来运行 <code v-pre>update-code</code> 和 <code v-pre>install-dependencies</code> 任务：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@servers(['web' =&gt; ['user@192.168.1.1']])</span>
<span class="line"></span>
<span class="line">@story('deploy')</span>
<span class="line">    update-code</span>
<span class="line">    install-dependencies</span>
<span class="line">@endstory</span>
<span class="line"></span>
<span class="line">@task('update-code')</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    git pull origin master</span>
<span class="line">@endtask</span>
<span class="line"></span>
<span class="line">@task('install-dependencies')</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    composer install</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>一旦故事编写完成，就可以像调用任务一样调用它：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php vendor/bin/envoy run deploy</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="钩子" tabindex="-1"><a class="header-anchor" href="#钩子"><span>钩子</span></a></h3>
<p>当任务和故事运行时，会执行一些钩子。Envoy 支持的钩子类型有 <code v-pre>@before</code>、<code v-pre>@after</code>、<code v-pre>@error</code>、<code v-pre>@success</code> 和 <code v-pre>@finished</code>。这些钩子中的所有代码都被解释为 PHP 并在本地执行，而不是在任务与之交互的远程服务器上执行。</p>
<p>你可以根据需要定义任意数量的这些钩子。它们将按照在 Envoy 脚本中出现的顺序执行。</p>
<h4 id="before" tabindex="-1"><a class="header-anchor" href="#before"><span><code v-pre>@before</code></span></a></h4>
<p>在每个任务执行之前，Envoy 脚本中注册的所有 <code v-pre>@before</code> 钩子都将执行。<code v-pre>@before</code> 钩子接收将要执行的任务名称：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@before</span>
<span class="line">    if ($task === 'deploy') {</span>
<span class="line">        // ...</span>
<span class="line">    }</span>
<span class="line">@endbefore</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="after" tabindex="-1"><a class="header-anchor" href="#after"><span><code v-pre>@after</code></span></a></h4>
<p>在每个任务执行之后，Envoy 脚本中注册的所有 <code v-pre>@after</code> 钩子都将执行。<code v-pre>@after</code> 钩子接收已执行的任务名称：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@after</span>
<span class="line">    if ($task === 'deploy') {</span>
<span class="line">        // ...</span>
<span class="line">    }</span>
<span class="line">@endafter</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="error" tabindex="-1"><a class="header-anchor" href="#error"><span><code v-pre>@error</code></span></a></h4>
<p>在每个任务失败（退出状态码大于 <code v-pre>0</code>）后，Envoy 脚本中注册的所有 <code v-pre>@error</code> 钩子都将执行。<code v-pre>@error</code> 钩子接收已执行的任务名称：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@error</span>
<span class="line">    if ($task === 'deploy') {</span>
<span class="line">        // ...</span>
<span class="line">    }</span>
<span class="line">@enderror</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="success" tabindex="-1"><a class="header-anchor" href="#success"><span><code v-pre>@success</code></span></a></h4>
<p>如果所有任务都已执行且没有错误，Envoy 脚本中注册的所有 <code v-pre>@success</code> 钩子都将执行：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@success</span>
<span class="line">    // ...</span>
<span class="line">@endsuccess</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="finished" tabindex="-1"><a class="header-anchor" href="#finished"><span><code v-pre>@finished</code></span></a></h4>
<p>在所有任务执行完毕后（无论退出状态如何），所有 <code v-pre>@finished</code> 钩子都将执行。<code v-pre>@finished</code> 钩子接收已完成任务的状态码，该状态码可能是 <code v-pre>null</code> 或大于等于 <code v-pre>0</code> 的整数：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    if ($exitCode &gt; 0) {</span>
<span class="line">        // 其中一项任务出错了...</span>
<span class="line">    }</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="运行任务" tabindex="-1"><a class="header-anchor" href="#运行任务"><span>运行任务</span></a></h2>
<p>要运行在应用程序的 <code v-pre>Envoy.blade.php</code> 文件中定义的任务或故事，请执行 Envoy 的 <code v-pre>run</code> 命令，并传递你要执行的任务或故事的名称。Envoy 将执行任务，并在任务运行时显示来自远程服务器的输出：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php vendor/bin/envoy run deploy</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="确认任务执行" tabindex="-1"><a class="header-anchor" href="#确认任务执行"><span>确认任务执行</span></a></h3>
<p>如果你想要在运行给定任务之前提示确认，应在任务声明中添加 <code v-pre>confirm</code> 指令。此选项对于破坏性操作特别有用：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@task('deploy', ['on' =&gt; 'web', 'confirm' =&gt; true])</span>
<span class="line">    cd /home/user/example.com</span>
<span class="line">    git pull origin {{ $branch }}</span>
<span class="line">    php artisan migrate</span>
<span class="line">@endtask</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="通知" tabindex="-1"><a class="header-anchor" href="#通知"><span>通知</span></a></h2>
<h3 id="slack" tabindex="-1"><a class="header-anchor" href="#slack"><span>Slack</span></a></h3>
<p>Envoy 支持在每个任务执行后发送通知到 <a href="https://slack.com/" target="_blank" rel="noopener noreferrer">Slack</a>。<code v-pre>@slack</code> 指令接受一个 Slack 钩子 URL 和一个频道/用户名。你可以通过在 Slack 控制面板中创建一个「Incoming WebHooks」集成来获取你的 Webhook URL。</p>
<p>你应将整个 Webhook URL 作为传递给 <code v-pre>@slack</code> 指令的第一个参数。传递给 <code v-pre>@slack</code> 指令的第二个参数应是一个频道名称（<code v-pre>#channel</code>）或用户名（<code v-pre>@user</code>）：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    @slack('webhook-url', '#bots')</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>默认情况下，Envoy 通知将发送一条消息到通知频道，描述已执行的任务。但是，你可以通过向 <code v-pre>@slack</code> 指令传递第三个参数来覆盖此消息，使用你自己的自定义消息：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    @slack('webhook-url', '#bots', 'Hello, Slack.')</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="discord" tabindex="-1"><a class="header-anchor" href="#discord"><span>Discord</span></a></h3>
<p>Envoy 还支持在每个任务执行后发送通知到 <a href="https://discord.com/" target="_blank" rel="noopener noreferrer">Discord</a>。<code v-pre>@discord</code> 指令接受一个 Discord 钩子 URL 和一个消息。你可以通过在你的服务器设置中创建一个「Webhook」并选择 Webhook 应发到的频道来获取你的 Webhook URL。你应将整个 Webhook URL 传递给 <code v-pre>@discord</code> 指令：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    @discord('discord-webhook-url')</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="telegram" tabindex="-1"><a class="header-anchor" href="#telegram"><span>Telegram</span></a></h3>
<p>Envoy 还支持在每个任务执行后发送通知到 <a href="https://telegram.org/" target="_blank" rel="noopener noreferrer">Telegram</a>。<code v-pre>@telegram</code> 指令接受一个 Telegram Bot ID 和一个 Chat ID。你可以通过使用 <a href="https://t.me/botfather" target="_blank" rel="noopener noreferrer">BotFather</a> 创建一个新机器人来获取你的 Bot ID。可以使用 <a href="https://t.me/username_to_id_bot" target="_blank" rel="noopener noreferrer">@username_to_id_bot</a> 获取有效的 Chat ID。你应将整个 Bot ID 和 Chat ID 传递给 <code v-pre>@telegram</code> 指令：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    @telegram('bot-id','chat-id')</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="microsoft-teams" tabindex="-1"><a class="header-anchor" href="#microsoft-teams"><span>Microsoft Teams</span></a></h3>
<p>Envoy 还支持在每个任务执行后发送通知到 <a href="https://www.microsoft.com/en-us/microsoft-teams" target="_blank" rel="noopener noreferrer">Microsoft Teams</a>。<code v-pre>@microsoftTeams</code> 指令接受一个 Teams Webhook（必需）、一个消息、主题颜色（success、info、 warning、 error）和一个选项数组。你可以通过创建一个新的 <a href="https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook" target="_blank" rel="noopener noreferrer">incoming webhook</a> 来获取你的 Teams Webhook。Teams API 有许多其他属性可以自定义你的消息框，如标题、摘要和部件。你可以在 <a href="https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#example-of-connector-message" target="_blank" rel="noopener noreferrer">Microsoft Teams 文档</a> 中找到更多信息。你应将整个 Webhook URL 传递给 <code v-pre>@microsoftTeams</code> 指令：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">@finished</span>
<span class="line">    @microsoftTeams('webhook-url')</span>
<span class="line">@endfinished</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/envoymd/16717" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/en...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/envoymd/16717" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/en...</a></p>
</blockquote>
</div></template>


